﻿<html>
<head>
    <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
    <script>
        var com_lipengbo_apps_xsnj = null;
        function checkTab(tabId, changeInfo, tab) {
            var url = tab.url;
            if (url.match(/^http[s]?:\/\/.*/)) {
                var newUrl = "http://h2w.iask.cn/hd.php?&psize=12800&url=" + url;
                $.ajax({
                    type:"POST",
                    url:newUrl,
                    data:null,
                    dataType:"html",
                    success:function (source) {
                        if (source.indexOf("txt_404") > -1) {
                            //Not Found
                        } else {
                            com_lipengbo_apps_xsnj = delAD(source);
                            if (localStorage["com_lipengbo_apps_xsnj_isauto"] == "true") {
                                pageIconClick(tab);
                            } else {
                                //Show the page action.
                                chrome.pageAction.show(tabId);
                            }
                        }
                    }
                });
            } else {
                //do nothing.
            }
        }

        function pageIconClick(tab) {
            chrome.pageAction.hide(tab.id);
            chrome.tabs.sendRequest(tab.id, {com_lipengbo_apps_xsnj:com_lipengbo_apps_xsnj}, function (response) {
                if (response == true) {
                    chrome.tabs.executeScript(null, {code:"NeoLi_Xsnj();"});
                }
            });
        }

        function onRequestAction(request, sender, callback) {
            if (request.jQueryAdded == 0) {
                chrome.tabs.executeScript(null, {file:"js/jquery-1.4.4.min.js"});
                chrome.tabs.executeScript(null, {file:"js/jquery-ui.min.js"});
                //chrome.tabs.executeScript(null, {code:"NeoLi_addCSS();"});
                callback({jQueryAdded:1});
            } else if (request.showPageAction == 0) {
                chrome.tabs.getCurrent(function (tab) {
                    chrome.pageAction.show(tab.id);
                });
            }
        }

        function delAD(source) {
            while (source.indexOf("<!--") > -1) {
                var start = source.indexOf("<!--");
                var end = source.indexOf("-->");
                source = source.substr(0, start) + source.substr(end + 3, source.length - 1 - end - 3);
            }
            source = source.replace("爱问", "大挪移正文提取");
            return source;
        }

        // Listen for any changes to the URL of any tab.
        chrome.tabs.onUpdated.addListener(checkTab);
        // Listen for pageAction
        chrome.pageAction.onClicked.addListener(pageIconClick);
        // Listen for Request
        chrome.extension.onRequest.addListener(onRequestAction);
    </script>
</head>
</html>